<template>
    <div>
    </div>
</template>

<script>
import { mapActions, mapState } from 'vuex';
import * as types from '@/api/login/types';
import { sleep } from '@/utils';
import { setToken, setDataType, setAppId, jsEncrypt } from '@/assets/js/auth';
import {postCallback,updateWeChatBinding} from '@/api/common/auth/userInfo/index.js'
// import {weChatCallback,doLogin,initLogin, getUserInfo,sendPhoneCode,roleDetail,setUserRole} from '@/api/login/index';
import Cookies from 'js-cookie'
export default {
    name:"getAccessToken",
    data() {
        return {
            loginForm: {
                openid: '',
                loginType: '',
                appId:'',
            },
            selectionRole:[],
            isShowDialog:false,
            openid:"",
        }
    },
    mounted () {
      this.geCodeAndState()
    },
    methods: {
         ...mapActions('app', ['createLoginInfo']),
        geCodeAndState(){
            if(this.$route.query){
                let params={
                    "appId": localStorage.getItem("appId")?localStorage.getItem("appId"):'cyx',//后期根据各自厂端自己处理
                    "code": this.$route.query.code,
                    "state": this.$route.query.state
                    }
                postCallback(params).then(res=>{
                    console.log(res,"res")
                    // localStorage.setItem('openidwx', res.data.openid);
                    let params={
                        flag: res.data.flag,
                        openid: res.data.openid,
                        ...res.data.wechatInfo,
                        type:1,
                    }
                    Cookies.set("wxName",res.data.wechatInfo.nickname)
                    updateWeChatBinding(params).then(res=>{
                        if(res.type == 1){
                            this.$router.push('/admin/auth/userInfo')
                            // this.$router.go(0)
                        }else if(res.type == 2){
                            this.userNum=res.data
                            this.open2(params)
                        }
                    })
                }) 
            } 
        },
        open2(params) {
            this.$confirm(``, '提示', {
            confirmButtonText: '继续绑定',
            cancelButtonText: '取消',
            dangerouslyUseHTMLString: true,
            message: `<p>当前微信已绑定员工编号：<i>${this.userNum}</i></p><p>如继续绑定，则将于原账号进行解绑</p>`,
            type: 'warning'
            }).then(() => {
                params.type=2
                updateWeChatBinding(params).then(res=>{
                    // this.$message({
                    //     type: 'success',
                    //     message: '绑定成功!'
                    // });
                     this.$router.push('/admin/auth/userInfo')
                    //this.$router.go(0)
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });    
                this.$router.push('/admin/auth/userInfo')
            });
        },
       
    },
}
</script>

<style lang="less" scoped>
.dialogP{
  font-size: 17px;
  line-height: 50px;
  padding-left: 10px;
  display: inline-block;
}
.dialogP:hover{
  background: #5FB2F9;
}
</style>
